﻿// Upgrade NOTE: upgraded instancing buffer 'Props' to new syntax.

Shader "Alex/MainRoleFade" {
	Properties{

		[CurvedWorldBendSettings] _CurvedWorldBendSettings("5|1|1", Vector) = (0, 0, 0, 0)

		_FixedColor("Fixed Color(固有色)", Color) = (1,1,1,0)//固有色
		_MainTex("Albedo (RGB)", 2D) = "white" {}
		_Color("Albedo Color(纹理色）", Color) = (1,1,1,1)//正片叠底
		_Glossiness("Smoothness", Range(0,1)) = 0.5
		_Metallic("Metallic", Range(0,1)) = 0.0
		_Emission("Emission(自发光，叠加色)", Color) = (0,0,0,1)//自发光，叠加色
		_EmissionTex("Emission (RGB)", 2D) = "black" {}

		[HideInInspector] _Alpha("Alpha", Float) = 1
		[HideInInspector] _Cull("__cull", Float) = 2.0
	}
		SubShader{
			Tags { "RenderType" = "Opaque" "Queue" = "Geometry" /*"IgnoreProjector" = "True"*/ }

			LOD 200

			Cull[_Cull]

			CGPROGRAM
			#pragma surface surf Standard vertex:vert fullforwardshadows nolightmap nodynlightmap nodirlightmap novertexlights nofog nometa novertexlights//keepalpha

			#pragma target 3.5

			#pragma multi_compile_instancing

			#pragma shader_feature USE_ALPHA_FADE
			#pragma shader_feature USE_TEXTURE
			#pragma shader_feature USER_EMISSION_TEXTURE
			#pragma shader_feature ALWAYS_FACE_CAMERA
			#include "CommonCG.cginc"

			#define CURVEDWORLD_BEND_TYPE_LITTLEPLANET_Y
			#define CURVEDWORLD_BEND_ID_1
			#pragma shader_feature_local CURVEDWORLD_DISABLED_ON
			#pragma shader_feature_local CURVEDWORLD_NORMAL_TRANSFORMATION_ON
			#include "Assets/Amazing Assets/Curved World/Shaders/Core/CurvedWorldTransform.cginc"

			fixed4 _Color;
			fixed4 _FixedColor;
			sampler2D _MainTex;
			#if USER_EMISSION_TEXTURE
			sampler2D _EmissionTex;
			#endif

			//float _MainRoleAlpha = 1;
			float _Alpha = 1;
			fixed3 _Emission;
			half _Glossiness;
			half _Metallic;


			struct Input {
				float4 screenPos;
				float4 color;
				fixed3 emission;
			};

			void vert(inout appdata_full v, out Input o) 
			{
				UNITY_INITIALIZE_OUTPUT(Input,o);

#if defined(CURVEDWORLD_IS_INSTALLED) && !defined(CURVEDWORLD_DISABLED_ON)
#ifdef CURVEDWORLD_NORMAL_TRANSFORMATION_ON
				CURVEDWORLD_TRANSFORM_VERTEX_AND_NORMAL(v.vertex, v.normal, v.tangent)
#else
				CURVEDWORLD_TRANSFORM_VERTEX(v.vertex)
#endif
#endif
				o.color = _Color;
				#if USE_TEXTURE
				o.color = _Color * tex2Dlod(_MainTex, v.texcoord);
				#endif
				o.emission = _Emission;
				#if USER_EMISSION_TEXTURE
				o.emission *= tex2Dlod(_EmissionTex, v.texcoord);
				#endif
				#if ALWAYS_FACE_CAMERA
				float3 viewDir = ObjSpaceViewDir(v.vertex);
				v.normal *= (1 + step(dot(viewDir, v.normal), 0)*-2);
				#endif
			}

			// Declare instanced properties inside a cbuffer.
			// Each instanced property is an array of by default 500(D3D)/128(GL) elements. Since D3D and GL imposes a certain limitation
			// of 64KB and 16KB respectively on the size of a cubffer, the default array size thus allows two matrix arrays in one cbuffer.
			// Use maxcount option on #pragma instancing_options directive to specify array size other than default (divided by 4 when used
			// for GL).
			UNITY_INSTANCING_BUFFER_START(Props)
			UNITY_INSTANCING_BUFFER_END(Props)

			void surf(Input IN, inout SurfaceOutputStandard o) {
				fixed4 c = IN.color;
				o.Metallic = _Metallic;
				o.Smoothness = _Glossiness;
				o.Emission = IN.emission;
				o.Albedo = lerp(c.rgb, _FixedColor.rgb, _FixedColor.a);
				o.Alpha = c.a;
				//o.Alpha *= _MainRoleAlpha;
				#if USE_ALPHA_FADE
				o.Alpha *= _Alpha;
				#endif
				ClipOnAlpha(o.Alpha, IN.screenPos);
			}
			ENDCG
		}

		FallBack "Diffuse"

		CustomEditor "MainRoleShaderEditor"
}
